class Twitter {
    posts: Map<number, number>[];
    followMap: Map<number, number[]>;
    constructor() {
        this.posts = [];
        this.followMap = new Map();
    }

    postTweet(userId: number, tweetId: number): void {
        const _post: Map<number, number> = new Map();
        _post.set(userId, tweetId);
        this.posts.unshift(_post);
    }

    getNewsFeed(userId: number): number[] {
        const ids = this.followMap.get(userId) || [];
        if (ids.indexOf(userId) === -1) {
            ids.push(userId);
        }

        return this.posts
            .map((_post) => Array.from(_post.entries()))
            .filter(([items]) => ids.indexOf(items[0]) > -1)
            .map(([items]) => items[1])
            .slice(0, 10);
    }

    follow(followerId: number, followeeId: number): void {
        const hasFollowed = this.followMap.get(followerId) || [];
        this.followMap.set(followerId, hasFollowed.concat([followeeId]));
    }

    unfollow(followerId: number, followeeId: number): void {
        const hasFollowed = this.followMap.get(followerId) || [];
        const index = hasFollowed.indexOf(followeeId);
        if (index < 0) {
            return;
        }

        hasFollowed.splice(index, 1);
        this.followMap.set(followerId, hasFollowed);
    }
}

/**
 * Your Twitter object will be instantiated and called as such:
 * var obj = new Twitter()
 * obj.postTweet(userId,tweetId)
 * var param_2 = obj.getNewsFeed(userId)
 * obj.follow(followerId,followeeId)
 * obj.unfollow(followerId,followeeId)
 */
